<template>
    <a-card :bordered="false">

        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">
                    <!--查询条件设置-->
                                                    <a-col :xl="6" :lg="7" :md="8" :sm="24">
                                    <a-form-item label="用户名">
                                        <a-input placeholder="请输入username"
                                                 v-model="queryParam.username"></a-input>
                                    </a-form-item>
                                </a-col>
                                <a-col :xl="6" :lg="7" :md="8" :sm="24">
                                    <a-form-item label="名称">
                                        <a-input placeholder="请输入name"
                                                 v-model="queryParam.name"></a-input>
                                    </a-form-item>
                                </a-col>
                                <a-col :xl="6" :lg="7" :md="8" :sm="24">
                                    <a-form-item label="数据源类型：1-oracle  2-mysql 3-sqlserver">
                                        <j-dict-select-tag
                                                v-model="queryParam.databaseType"
                                                dictCode="database_type"
                                                placeholder="请选择databaseType"></j-dict-select-tag>
                                    </a-form-item>
                                </a-col>
                    <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
                    </a-col>

                </a-row>
            </a-form>
        </div>

        <!-- 操作按钮区域 -->
        <div class="table-operator">
            <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
            <a-button type="primary" icon="download" @click="handleExportXls('SysDatabaseConfig.xlsx')">导出
            </a-button>
            <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader"
                      :action="importExcelUrl" @change="handleImportExcel" :data="excelParam" >
                <a-button type="primary" icon="import">导入</a-button>
            </a-upload>
        </div>

        <!-- table区域-begin -->
        <div>
            <a-table
                    ref="table"
                    size="middle"
                    bordered
                    rowKey="id"
                    :columns="columns"
                    :dataSource="dataSource"
                    :pagination="ipagination"
                    :loading="loading"
                    class="j-table-force-nowrap"
                    :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
                    @change="handleTableChange">
                        <span slot="action" slot-scope="text, record">

                          <a @click="handleEdit(record)">编辑</a>
                          <a-divider type="vertical"/>
                          <a-dropdown>
                            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
                            <a-menu slot="overlay">
                              <a-menu-item>
                                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                                  <a>删除</a>
                                </a-popconfirm>
                              </a-menu-item>
                            </a-menu>
                          </a-dropdown>
                        </span>
            </a-table>
        </div>
        <!-- table区域-end -->

        <!-- 表单区域 -->
        <SysDatabaseConfigModal ref="modalForm" @ok="modalFormOk"></SysDatabaseConfigModal>
    </a-card>
</template>

<script>
    import SysDatabaseConfigModal from './modules/SysDatabaseConfigModal'
    import {JeecgListMixin} from '@/mixins/JeecgListMixin'

    export default {
        name: "SysDatabaseConfigList",
        mixins: [JeecgListMixin],
        components: {
            SysDatabaseConfigModal
        },
        data() {
            return {
                description: '数据源配置表管理页面',
                // 表头
                columns: [
                    {
                        title: '#',
                        dataIndex: '',
                        key: 'rowIndex',
                        width: 60,
                        align: "center",
                        customRender: function (t, r, index) {
                            return parseInt(index) + 1;
                        }
                    },
                    {
                        align: 'left',
                        sorter:true,
                        title: '数据库连接',
                        dataIndex: 'url',
                    },
                    {
                        align: 'left',
                        sorter:true,
                        title: '用户名',
                        dataIndex: 'username',
                    },
                    {
                        align: 'left',
                        sorter:true,
                        title: '驱动类',
                        dataIndex: 'driverClass',
                    },
                    {
                        align: 'left',
                        sorter:true,
                        title: '名称',
                        dataIndex: 'name',
                    },
                    {
                        align: 'left',
                        sorter:true,
                        title: '数据源类型：1-oracle  2-mysql 3-sqlserver',
                        dataIndex: 'databaseType_dictText',
                    },
                    {
                        title: '操作',
                        dataIndex: 'action',
                        align: "center",
                        scopedSlots: {customRender: 'action'},
                    }
                ],
                url: {
                    list: "/genertator/SysDatabaseConfig/list",
                    delete: "/genertator/SysDatabaseConfig/delete",
                    excelConfig: "genertator/SysDatabaseConfig/excelConfig"
                },
            }
        },
        created() {
            this.isorter = {
                column: 'name',
                order: 'desc',
            }
        },
        computed: {},
        methods: {}
    }
</script>
<style scoped>
    @import '~@assets/less/common.less';
</style>
